home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / chat / reflect.000 / reflect / 3.0b3 / control.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  11.3 KB  |  435 lines

  1. /*
  2.  
  3. Copyright 1993, 1994, Cornell University
  4.  
  5. Cornell hereby grants permission to use, copy, modify, and distribute this program for any purpose 
  6. and without fee, provided that these copyright and permission notices appear on all copies and 
  7. supporting documentation, the name of Cornell not be used in advertising or publicity pertaining 
  8. to distribution of the program without specific prior permission, notice be given in supporting 
  9. documentation that copying and distribution is by permission of Cornell.  CORNELL MAKES NO 
  10. REPRESENTATIONS OR WARRANTEES, EXPRESS OR IMPLIED.  By way of example, but not limitation, 
  11. CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR 
  12. PURPOSE OR THAT THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, 
  13. TRADEMARKS, OR OTHER RIGHTS.  Cornell shall not be held liable for any liability with respect to 
  14. any claim by the user or any other party arising from use of the program.
  15.  
  16. This material is partially based on work sponsored by the National Science Foundation under Cooperative 
  17. Agreement No. NCR-9318337.  The government has certain rights in this material.
  18.  
  19. */
  20.  
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <signal.h>
  25. #include <errno.h>
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28.  
  29. #ifndef LINUX
  30. #include <sys/socketvar.h>
  31. #endif
  32.  
  33. #include <netinet/in.h>
  34.  
  35. #include "reflect.h"
  36. #include "refmon.h"
  37. #include "globals.h"
  38.  
  39. process_control_pkt(conpkt)
  40.     RefConPkt *conpkt;
  41. {
  42.     RefConPkt        pkt;
  43.     client           *ctmp;
  44.     char             buf[255],*bptr;
  45.     short            total_len,len,cnt;
  46.     int              argc;
  47.     char             **argv;
  48.     struct in_addr   in;
  49.  
  50.     switch(ntohs(conpkt->msg_type))
  51.     {
  52.        case TERM:
  53.           dolog("TERM received on control socket\n");
  54.           exit(1);
  55.  
  56.        case VERSION:
  57.           dolog("VERSION received on control socket\n");
  58.           pkt.msg_type = htons(VERSION);
  59.           pkt.msg_len = htons(MINREFPKT + sizeof(VERSION_STRING));
  60.           bcopy(VERSION_STRING,pkt.msg_data,sizeof(VERSION_STRING));
  61.  
  62.           if (write(msg_sock,&pkt,ntohs(pkt.msg_len)) == -1)
  63.              my_perror("write version number");
  64.  
  65.           return;
  66.  
  67.        case UPTIME:
  68.           dolog("UPTIME received on control socket\n");
  69.           pkt.msg_type = htons(UPTIME);
  70.           pkt.msg_len = htons(MINREFPKT + strlen(start_time));
  71.           bcopy(start_time,pkt.msg_data,strlen(start_time));
  72.  
  73.           if (write(msg_sock,&pkt,ntohs(pkt.msg_len)) == -1)
  74.              my_perror("write uptime");
  75.  
  76.           return;
  77.  
  78.        case WHO:
  79.           dolog("WHO received on control socket\n");
  80.           write_clients();
  81.           return;
  82.  
  83.        case MAVEN:
  84.           dolog("MAVEN received on control socket\n");
  85.           write_mclients();
  86.           return;
  87.  
  88.        case PARAM:
  89.           dolog("PARAM received on control socket\n");
  90.  
  91.           len = strlen(conf_buf);
  92.  
  93.           sprintf(&conf_buf[len],"\nCurrent conference id %d\n",conference_id);
  94.  
  95.           pkt.msg_type = htons(PARAM);
  96.           pkt.msg_len = htons(MINREFPKT + strlen(conf_buf));
  97.           bptr = pkt.msg_data;
  98.           
  99.           strcpy(bptr,conf_buf);
  100.  
  101.           if (write(msg_sock,&pkt,ntohs(pkt.msg_len)) == -1)
  102.              my_perror("control write  param");
  103.  
  104.           conf_buf[len] = 0;
  105.  
  106.           return;
  107.  
  108.        default:
  109.           dolog("UNKNOWN type received on control socket\n");
  110.           return;
  111.  
  112.     }
  113. }
  114.  
  115. write_clients()
  116. {
  117.     RefConPkt        pkt;
  118.     client           *ctmp;
  119.     char             buf[255],tmp[100];
  120.     short            total_len,len;
  121.     struct in_addr   in;
  122.  
  123.     pkt.msg_type = htons(WHO);
  124.     ctmp = chead;
  125.  
  126.     if (ctmp == NULL)
  127.     {
  128.        strcpy(pkt.msg_data,"No Clients");
  129.        pkt.msg_len = htons(MINREFPKT + strlen("No Clients"));
  130.  
  131.        if (write(msg_sock,&pkt,ntohs(pkt.msg_len)) == -1)
  132.           my_perror("control write write_clients");
  133.  
  134.        return;
  135.     }
  136.  
  137.     total_len = 0;
  138.     while (ctmp != NULL)
  139.     {
  140.        if (ctmp->clnt_flags & CLIENT)
  141.           len = strlen("CLIENT: ");
  142.        else
  143.        if (ctmp->clnt_flags & BCC_CLIENT)
  144.           len = strlen("BCC_CLIENT: ");
  145.        else
  146.        if (ctmp->clnt_flags & BCC_SERVER)
  147.           len = strlen("BCC_SERVER: ");
  148.        else
  149.        if (ctmp->clnt_flags & BCC_ORIGIN)
  150.           len = strlen("BCC_ORIGIN: ");
  151.        else
  152.        if (ctmp->clnt_flags & REF1_CLIENT)
  153.           len = strlen("REF1_CLIENT: ");
  154.        else
  155.        if (ctmp->clnt_flags & REF1_SERVER)
  156.           len = strlen("REF1_SERVER: ");
  157.        else
  158.        if (ctmp->clnt_flags & REF1_ORIGIN)
  159.           len = strlen("REF1_ORIGIN: ");
  160.        else
  161.        if (ctmp->clnt_flags & REF2_SERVER)
  162.           len = strlen("REF2_SERVER: ");
  163.        else
  164.        if (ctmp->clnt_flags & REF2_ORIGIN)
  165.           len = strlen("REF2_ORIGIN: ");
  166.        else
  167.        if (ctmp->clnt_flags & REF3_SERVER)
  168.           len = strlen("REF3_SERVER: ");
  169.        else
  170.        if (ctmp->clnt_flags & REF3_ORIGIN)
  171.           len = strlen("REF3_ORIGIN: ");
  172.        else
  173.        if (ctmp->clnt_flags & NV_UCLIENT)
  174.           len = strlen("NV UNICAST: ");
  175.        else
  176.        if (ctmp->clnt_flags & NV_MCLIENT)
  177.           len = strlen("NV MULTICAST: ");
  178.        else 
  179.           len = strlen("UNKNOWN: ");
  180.  
  181.        if (strlen(ctmp->clnt_config.name) >= 20)
  182.           len += 19;
  183.        else
  184.           len += strlen(ctmp->clnt_config.name);
  185.  
  186.        in.s_addr = ctmp->clnt_addr.addr;
  187.        len += strlen(inet_ntoa(in));
  188.        total_len += (len + 2);
  189.  
  190.        /* save some room for the audio and video flags output */
  191.        total_len += 4;
  192.  
  193.        ctmp = ctmp->clnt_nptr;
  194.     }
  195.  
  196.     sprintf(tmp,"\nTotal # of clients %d  senders %d  lurkers %d\n",client_cnt,send_ccnt,lurker_ccnt);
  197.     total_len += strlen(tmp);
  198.  
  199.     pkt.msg_len = htons(MINREFPKT + total_len);
  200.     if (write(msg_sock,&pkt,MINREFPKT) == -1)
  201.        my_perror("control write write_clients");
  202.  
  203.     ctmp = chead;
  204.  
  205.     while (ctmp != NULL)
  206.     {
  207.        if (ctmp->clnt_flags & CLIENT)
  208.        {
  209.           len = strlen("CLIENT: ");
  210.           bcopy("CLIENT: ",buf,len);
  211.        }
  212.        else
  213.        if (ctmp->clnt_flags & BCC_CLIENT)
  214.        {
  215.           len = strlen("BCC_CLIENT: ");
  216.           bcopy("BCC_CLIENT: ",buf,len);
  217.        }
  218.        else
  219.        if (ctmp->clnt_flags & BCC_SERVER)
  220.        {
  221.           len = strlen("BCC_SERVER: ");
  222.           bcopy("BCC_SERVER: ",buf,len);
  223.        }
  224.        else
  225.        if (ctmp->clnt_flags & BCC_ORIGIN)
  226.        {
  227.           len = strlen("BCC_ORIGIN: ");
  228.           bcopy("BCC_ORIGIN: ",buf,len);
  229.        }
  230.        else
  231.        if (ctmp->clnt_flags & REF1_CLIENT)
  232.        {
  233.           len = strlen("REF1_CLIENT: ");
  234.           bcopy("REF1_CLIENT: ",buf,len);
  235.        }
  236.        else
  237.        if (ctmp->clnt_flags & REF1_SERVER)
  238.        {
  239.           len = strlen("REF1_SERVER: ");
  240.           bcopy("REF1_SERVER: ",buf,len);
  241.        }
  242.        else
  243.        if (ctmp->clnt_flags & REF1_ORIGIN)
  244.        {
  245.           len = strlen("REF1_ORIGIN: ");
  246.           bcopy("REF1_ORIGIN: ",buf,len);
  247.        }
  248.        else
  249.        if (ctmp->clnt_flags & REF2_SERVER)
  250.        {
  251.           len = strlen("REF2_SERVER: ");
  252.           bcopy("REF2_SERVER: ",buf,len);
  253.        }
  254.        else
  255.        if (ctmp->clnt_flags & REF2_ORIGIN)
  256.        {
  257.           len = strlen("REF2_ORIGIN: ");
  258.           bcopy("REF2_ORIGIN: ",buf,len);
  259.        }
  260.        else
  261.        if (ctmp->clnt_flags & REF3_SERVER)
  262.        {
  263.           len = strlen("REF3_SERVER: ");
  264.           bcopy("REF3_SERVER: ",buf,len);
  265.        }
  266.        else
  267.        if (ctmp->clnt_flags & REF3_ORIGIN)
  268.        {
  269.           len = strlen("REF3_ORIGIN: ");
  270.           bcopy("REF3_ORIGIN: ",buf,len);
  271.        }
  272.        else
  273.        if (ctmp->clnt_flags & NV_UCLIENT)
  274.        {
  275.           len = strlen("NV UNICAST: ");
  276.           bcopy("NV UNICAST: ",buf,len);
  277.        }
  278.        else
  279.        if (ctmp->clnt_flags & NV_MCLIENT)
  280.        {
  281.           len = strlen("NV MULTICAST: ");
  282.           bcopy("NV MULTICAST: ",buf,len);
  283.        }
  284.        else
  285.        {
  286.           len = strlen("UNKNOWN: ");
  287.           bcopy("UNKNOWN: ",buf,len);
  288.        }
  289.  
  290.        if (strlen(ctmp->clnt_config.name) >= 20)
  291.        {
  292.           bcopy(ctmp->clnt_config.name,&buf[len],19);
  293.           len += 19;
  294.        }
  295.        else
  296.        {
  297.           bcopy(ctmp->clnt_config.name,&buf[len],strlen(ctmp->clnt_config.name));
  298.           len += strlen(ctmp->clnt_config.name);
  299.        }
  300.  
  301.        buf[len] = '@';
  302.        total_len = len;
  303.  
  304.        in.s_addr = ctmp->clnt_addr.addr;
  305.        len = strlen(inet_ntoa(in));
  306.        bcopy(inet_ntoa(in),&buf[total_len+1],len);
  307.        total_len += len;
  308.  
  309.        buf[++total_len] = ' ';
  310.  
  311.        if (ctmp->clnt_config.flags & AUDIO_CAPABLE)
  312.           buf[++total_len] = 'C';
  313.        else
  314.           buf[++total_len] = ' ';
  315.  
  316.        if (ctmp->clnt_config.flags & REC_AUDIO)
  317.           buf[++total_len] = 'R';
  318.        else
  319.           buf[++total_len] = ' ';
  320.  
  321.        if (ctmp->clnt_config.sendMode)
  322.           buf[++total_len] = 'V';
  323.        else
  324.           buf[++total_len] = ' ';
  325.  
  326.  
  327.        buf[++total_len] = '\n';
  328.  
  329.        total_len++;
  330.  
  331.  
  332.        if (write(msg_sock,buf,total_len) != total_len)
  333.           my_perror("control write write_clients");
  334.  
  335.        ctmp = ctmp->clnt_nptr;
  336.     }
  337.  
  338.     if (write(msg_sock,tmp,strlen(tmp)) != strlen(tmp))
  339.        my_perror("control write write_clients");
  340.  
  341.     return;
  342. }
  343.  
  344. write_mclients()
  345. {
  346.     RefConPkt        pkt;
  347.     vat_client       *ctmp;
  348.     char             buf[255],tmp[100];
  349.     short            total_len,len;
  350.     struct in_addr   in;
  351.  
  352.     pkt.msg_type = htons(MAVEN);
  353.     ctmp = mhead;
  354.  
  355.     if (ctmp == NULL)
  356.     {
  357.        strcpy(pkt.msg_data,"No Maven Clients");
  358.        pkt.msg_len = htons(MINREFPKT + strlen("No Maven Clients"));
  359.  
  360.        if (write(msg_sock,&pkt,ntohs(pkt.msg_len)) == -1)
  361.           my_perror("control write write_mclients");
  362.  
  363.        return;
  364.     }
  365.  
  366.     total_len = 0;
  367.     while (ctmp != NULL)
  368.     {
  369.        if (ctmp->mvn_flags & VAT_CLIENT)
  370.           len = strlen("VAT_CLIENT: ");
  371.        else
  372.        if (ctmp->mvn_flags & VAT_MIXER)
  373.           len = strlen("VAT_MIXER: ");
  374.        else
  375.        if (ctmp->mvn_flags & VAT_MIXER_CLIENT)
  376.           len = strlen("VAT_MIXER_CLIENT: ");
  377.        else 
  378.           len = strlen("UNKNOWN: ");
  379.  
  380.        in.s_addr =  ctmp->mvn_addr.addr;
  381.        len += strlen(inet_ntoa(in));
  382.        total_len += (len + 1);
  383.        ctmp = ctmp->mvn_nptr;
  384.     }
  385.  
  386.     sprintf(tmp,"\nTotal # of vat clients %d\n",vat_client_cnt);
  387.     total_len += strlen(tmp);
  388.  
  389.     pkt.msg_len = htons(MINREFPKT + total_len);
  390.     if (write(msg_sock,&pkt,MINREFPKT) == -1)
  391.        my_perror("control write write_mclients");
  392.  
  393.     ctmp = mhead;
  394.  
  395.     while (ctmp != NULL)
  396.     {
  397.        if (ctmp->mvn_flags & VAT_CLIENT)
  398.        {
  399.           len = strlen("VAT_CLIENT: ");
  400.           bcopy("VAT_CLIENT: ",buf,len);
  401.        }
  402.        else
  403.        if (ctmp->mvn_flags & VAT_MIXER)
  404.        {
  405.           len = strlen("VAT_MIXER: ");
  406.           bcopy("VAT_MIXER: ",buf,len);
  407.        }
  408.        else
  409.        if (ctmp->mvn_flags & VAT_MIXER_CLIENT)
  410.        {
  411.           len = strlen("VAT_MIXER_CLIENT: ");
  412.           bcopy("VAT_MIXER_CLIENT: ",buf,len);
  413.        }
  414.        else
  415.        {
  416.           len = strlen("UNKNOWN: ");
  417.           bcopy("UNKNOWN: ",buf,len);
  418.        }
  419.  
  420.        in.s_addr = ctmp->mvn_addr.addr;
  421.        bcopy(inet_ntoa(in),&buf[len],strlen(inet_ntoa(in)));
  422.        len += strlen(inet_ntoa(in));
  423.        buf[len] = '\n';
  424.  
  425.        if (write(msg_sock,buf,len+1) != len+1)
  426.           my_perror("control write write_mclients");
  427.  
  428.        ctmp = ctmp->mvn_nptr;
  429.     }
  430.  
  431.     if (write(msg_sock,tmp,strlen(tmp)) != strlen(tmp))
  432.        my_perror("control write write_mclients");
  433. }
  434.  
  435.